package com.weifangfirecontrolformal.weifangfirecontrolformal.web.web.internetofthings.firefightingiot;

import cn.hutool.json.JSONObject;
import com.weifangfirecontrolformal.weifangfirecontrolformal.common.base.BaseController;
import com.weifangfirecontrolformal.weifangfirecontrolformal.support.annotaion.Action;
import com.weifangfirecontrolformal.weifangfirecontrolformal.support.annotaion.At;
import com.weifangfirecontrolformal.weifangfirecontrolformal.support.model.RespEntity;
import com.weifangfirecontrolformal.weifangfirecontrolformal.web.service.internetofthings.firefightingiot.IPBroadCastService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * @Author: YangYu
 * @ClassName: IPBroadCastController
 * @Date: Created in 9:44 2022/3/28
 * @Description:
 */
@Action
@RequestMapping("fireFightingIOT/ipbroadcast")
public class IPBroadCastController extends BaseController {

    @Resource
    private IPBroadCastService ipBroadCastService;


    /**
     * @Author YangYu
     * @Description 上传音乐到中转服务器
     * @Date Created in 10:52 2022/3/25
     * @Param [file]
     */

    @At(value = "/uploadMusic", method = RequestMethod.POST)
    public RespEntity uploadMusic(@RequestParam("file") MultipartFile file, String homeId) throws IOException {
        return ipBroadCastService.uploadMusic(file,homeId);
    }

    /**
     * @Author YangYu
     * @Description 删除音乐文件
     * @Date Created in 16:28 2022/3/25
     * @Param [jsonParam，id：文件id fileName：文件名]
     */

    @At(value = "deleteMusic", method = RequestMethod.POST, param = { "id","fileName"})
    public RespEntity updateServerMusicId(@RequestBody(required = false) JSONObject jsonParam){
        return ipBroadCastService.deleteMusic(jsonParam);
    }

    /**
     * @Author YangYu
     * @Description 获取音乐文件列表
     * @Date Created in 16:50 2022/3/25
     * @Param [jsonParam ]
     */

    @At(value = "getMusicFileList", method = RequestMethod.GET,param = {"homeId"})
    public RespEntity getMusicFileList(@RequestBody(required = false) JSONObject jsonParam) {
        return ipBroadCastService.getMusicFileList(jsonParam);
    }

    /**
     * @Author YangYu
     * @Description 批量播放音乐
     * @Date Created in 16:50 2022/3/25
     * @Param [jsonParam musicidlist:音乐的idlist deviceidarray:设备ID数组 model: 播放类型 1 单曲播放 2 单曲循环 3 随机播放 4 顺序播放 5 列表循环]
     */

    @At(value = "playMusicByList", method = RequestMethod.POST,param = {"musicidlist","deviceidarray","model"})
    public RespEntity playMusicByList(@RequestBody(required = false) JSONObject jsonParam) {
        return ipBroadCastService.playMusicByList(jsonParam);
    }

    /**
     * @Author YangYu
     * @Description 批量暂停播放
     * @Date Created in 14:07 2022/3/28
     * @Param [jsonParam]
     */

    @At(value = "stopMusic", method = RequestMethod.POST,param = {"deviceidarray"})
    public RespEntity stopMusic(@RequestBody(required = false) JSONObject jsonParam) {
        return ipBroadCastService.stopMusic(jsonParam);
    }

    /**
     * @Author YangYu
     * @Description 批量播放TTS
     * @Date Created in 17:09 2022/3/25
     * @Param [jsonParam deviceidarray:设备ID数组 字符串数组. 例如 ["455","357","2947_3"]  text:播放内容.例如 “锄禾日当午，汗滴禾下土” times: 播放次数.例如 3 1到200之间]
     */

    @At(value = "ttsPlayMusic", method = RequestMethod.POST,param = {"deviceidarray","text","times"})
    public RespEntity ttsPlayMusic(@RequestBody(required = false) JSONObject jsonParam) {
        return ipBroadCastService.ttsPlayMusic(jsonParam);
    }


    /**
     * @Author YangYu
     * @Description 监听
     * @Date Created in 17:16 2022/3/25
     * @Param [jsonParam monitordevid:监听设备ID monitoreddevid:被监听设备ID model:1-输出监听，2-现场监听]
     */

    @At(value = "monitor", method = RequestMethod.POST,param = {"monitordevid","monitoreddevid","model"})
    public RespEntity monitor(@RequestBody(required = false) JSONObject jsonParam) {
        return ipBroadCastService.monitor(jsonParam);
    }

    /**
     * @Author YangYu
     * @Description 停止监听
     * @Date Created in 17:22 2022/3/25
     * @Param [jsonParam monitoreddevid：被监听设备id]
     */

    @At(value = "stopMonitor", method = RequestMethod.POST,param = {"monitoreddevid"})
    public RespEntity stopMonitor(@RequestBody(required = false) JSONObject jsonParam) {
        return ipBroadCastService.stopMonitor(jsonParam);
    }

    /**
     * @Author YangYu
     * @Description 调节音量
     * @Date Created in 17:25 2022/3/25
     * @Param [jsonParam deviceidarray:设备ID数组.例如 [3005,2888,2947] vol:音量值 例如 50]
     */

    @At(value = "setvol", method = RequestMethod.POST,param = {"deviceidarray","vol"})
    public RespEntity setvol(@RequestBody(required = false) JSONObject jsonParam) {
        return ipBroadCastService.setvol(jsonParam);
    }

    /**
     * @Author YangYu
     * @Description 获取设备状态信息
     * @Date Created in 17:25 2022/3/25
     * @Param [jsonParam ]
     */

    @At(value = "getDevicesInfo", method = RequestMethod.GET,param = {"number"})
    public RespEntity getDevicesInfo(@RequestBody(required = false) JSONObject jsonParam) {
        return ipBroadCastService.getDevicesInfo(jsonParam);
    }
}
